package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;


    @PostMapping("/submit")
    public R submit(@RequestBody Orders orders){
        log.info("订单数据:{}",orders);
        orderService.submit(orders);
        return R.success("下单成功");
    }


    /**
     *
     * 订单明细
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public R page(int page,int pageSize){
        Page<Orders>ordersPage = new Page<>(page,pageSize);
        LambdaQueryWrapper<Orders>queryWrapper = new LambdaQueryWrapper<Orders>();
        queryWrapper.orderByDesc(Orders ::getOrderTime);
        orderService.page(ordersPage,queryWrapper);
        return R.success(ordersPage);
    }

    /**
     *
     * 订单明细分页查询
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/userPage")
    public R userPage(int page,int pageSize){
        Page<Orders> ordersPage = new Page<>(page, pageSize);

        return R.success(ordersPage);
    }


}
